home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / pack / xfh132.lzh / XFH / src / Packet.c < prev    next >
C/C++ Source or Header  |  1993-01-19  |  4KB  |  129 lines

  1. /* Packet.c - general, lo-level packet handling routines.
  2.    Copyright (C) 1991, 1992, 1993 Kristian Nielsen.
  3.  
  4.    This file is part of XFH, the compressing file system handler.
  5.  
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            */
  19.  
  20. /* $Log:    Packet.c,v $
  21.  * Revision 1.2  93/01/14  15:29:41  Kristian
  22.  * Added RCS keywords.
  23.  * 
  24.  */
  25.  
  26.  
  27. #include <exec/types.h>
  28. #include <exec/ports.h>
  29. #include <libraries/dos.h>
  30. #include <libraries/dosextens.h>
  31.  
  32. #include <proto/exec.h>
  33.  
  34. #include <stdarg.h>
  35.  
  36. /*
  37.  * Send an already allocate packet, with given arguments, to a handler.
  38.  * retport is the port that the packet should return to. This function will
  39.  * NOT wait for the packet to return. numarg specifies how many arguments
  40.  * follow after it (arguments will be treated as LONG).
  41.  *
  42.  * Use this function for doing async IO with DOS handlers.
  43.  */
  44.  
  45. void putpkt(struct StandardPacket *pkt,struct MsgPort *procid,
  46.            struct MsgPort *retport,LONG type,int numarg,...){
  47.    va_list vl;
  48.    LONG *p;
  49.    
  50.    /* Allow for variable number of parameters in a packet. */
  51.    va_start(vl,numarg);
  52.    
  53.    /* Set up fields for packet handling. */
  54.    pkt->sp_Msg.mn_Node.ln_Succ=pkt->sp_Msg.mn_Node.ln_Pred=NULL;
  55.    pkt->sp_Msg.mn_Node.ln_Name=(char *)&pkt->sp_Pkt;
  56.    pkt->sp_Msg.mn_Node.ln_Type=NT_MESSAGE;
  57.    pkt->sp_Msg.mn_Node.ln_Pri=0;
  58.    pkt->sp_Msg.mn_ReplyPort=NULL;
  59.    pkt->sp_Msg.mn_Length=sizeof(*pkt);
  60.    pkt->sp_Pkt.dp_Port=retport;
  61.    pkt->sp_Pkt.dp_Link=&pkt->sp_Msg;
  62.  
  63.    /* Set up packet args. First the packet request type. */
  64.    pkt->sp_Pkt.dp_Type=type;
  65.    
  66.    /* Handle each of the arguments in turn. */
  67.    p=&pkt->sp_Pkt.dp_Arg1;
  68.    while(numarg--){
  69.       *p++=va_arg(vl,LONG);
  70.    }
  71.    
  72.    /* And finally, set the packet off on its way to the handler. */
  73.    PutMsg(procid,&pkt->sp_Msg);
  74.    
  75.    va_end(vl);
  76. }
  77.  
  78.  
  79. /*
  80.  * Send an already allocated packet to an AmigaDOS handler using
  81.  * supplied arguments, wait for the reply and return dp_Res1 & dp_Res2.
  82.  *
  83.  * Use this for doing syncronous IO just like dos.library, but using
  84.  * a private message port.
  85.  */
  86.  
  87. LONG dopkt(struct StandardPacket *pkt,struct MsgPort *procid,
  88.            struct MsgPort *retport,LONG *res2,LONG type,int numarg,...){
  89.    va_list vl;
  90.    LONG *p;
  91.    struct Message *msg;
  92.    
  93.    /* Set up fields for packet handling. */
  94.    pkt->sp_Msg.mn_Node.ln_Succ=pkt->sp_Msg.mn_Node.ln_Pred=NULL;
  95.    pkt->sp_Msg.mn_Node.ln_Name=(char *)&pkt->sp_Pkt;
  96.    pkt->sp_Msg.mn_Node.ln_Type=NT_MESSAGE;
  97.    pkt->sp_Msg.mn_Node.ln_Pri=0;
  98.    pkt->sp_Msg.mn_ReplyPort=NULL;
  99.    pkt->sp_Msg.mn_Length=sizeof(*pkt);
  100.    pkt->sp_Pkt.dp_Port=retport;
  101.    pkt->sp_Pkt.dp_Link=&pkt->sp_Msg;
  102.  
  103.    /* Set up packet args. First the packet request type. */
  104.    pkt->sp_Pkt.dp_Type=type;
  105.    
  106.    /* Handle each of the arguments in turn. */
  107.    /* Allow for variable number of parameters in a packet. */
  108.    va_start(vl,numarg);   
  109.    p=&pkt->sp_Pkt.dp_Arg1;
  110.    while(numarg--){
  111.       *p++=va_arg(vl,LONG);
  112.    }
  113.    va_end(vl);
  114.    
  115.    /* And finally, set the packet off on its way to the handler. */
  116.    PutMsg(procid,&pkt->sp_Msg);
  117.    
  118.    /*
  119.     * Wait for the reply. NOTE: Make SURE no other messages arrive first
  120.     * at this port!
  121.     */
  122.    while(!(msg=GetMsg(retport))) WaitPort(retport);
  123.    
  124.    if(res2)  /* Allow for NULL 'don't care' pointer. */
  125.       *res2=pkt->sp_Pkt.dp_Res2;
  126.    return pkt->sp_Pkt.dp_Res1;
  127. }
  128.  
  129.